package com.huike.web.controller.report;


import com.huike.report.domain.vo.IndexTodayInfoVO;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }

    /**
     * 获取今日线索啊商机啊什么的数据
     * @return
     */
    @GetMapping("/getTodayInfo")
    public AjaxResult todayCluesNum(){
        IndexTodayInfoVO indexTodayInfoVO=new IndexTodayInfoVO();
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式(年-月-日-时-分-秒)
        String createTime = dateFormat.format(now);//格式化然后放入字符串中
        //获取今日线索
        Integer todayCluesNum = reportService.getTodayCluesNum(createTime);
        //获取今日商机
        Integer todayBusinessNum = reportService.getTodayBusinessNum(createTime);
        //获取今日合同
        Integer todayContractNum = reportService.getTodayContractNum(createTime);
        //获取今日金额
        Double todaySalesAmount = reportService.getTodaySalesAmount(createTime);

        indexTodayInfoVO.setTodayCluesNum(todayCluesNum);
        indexTodayInfoVO.setTodayBusinessNum(todayBusinessNum);
        indexTodayInfoVO.setTodayContractNum(todayContractNum);
        indexTodayInfoVO.setTodaySalesAmount(todaySalesAmount);
        /*Map<String,Object> map=new HashMap();
        map.put("todayCluesNum",todayCluesNum);
        map.put("todayBusinessNum",todayBusinessNum);
        map.put("todayContractNum",todayContractNum);
        map.put("todaySalesAmount",todaySalesAmount);*/
        return AjaxResult.success("操作成功",indexTodayInfoVO);
    }

    /**
     * 待办数据统计接口
     * @return
     */
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(String beginCreateTime,String endCreateTime){
        IndexTodoInfoVO indexTodoInfoVO=new IndexTodoInfoVO();
        Integer tofollowedCluesNum = reportService.tofollowedCluesNum(beginCreateTime, endCreateTime);
        Integer tofollowedBusinessNum = reportService.tofollowedBusinessNum(beginCreateTime, endCreateTime);
        Integer toallocatedCluesNum = reportService.toallocatedCluesNum(beginCreateTime, endCreateTime);
        Integer toallocatedBusinessNum = reportService.toallocatedBusinessNum(beginCreateTime, endCreateTime);
        indexTodoInfoVO.setTofollowedCluesNum(tofollowedCluesNum);
        indexTodoInfoVO.setTofollowedBusinessNum(tofollowedBusinessNum);
        indexTodoInfoVO.setToallocatedCluesNum(toallocatedCluesNum);
        indexTodoInfoVO.setToallocatedBusinessNum(toallocatedBusinessNum);
        return AjaxResult.success("操作成功",indexTodoInfoVO);
    }


}